<?php

class News_Controller extends Template_Controller {



	public $template = 'client/index';

	

    public function __construct()

    {

        parent::__construct();

        

        //Css

        //$this->template->css = $this->site['theme_url'].'index/article.css';

       

    }

    

	public function __call($method, $arguments)

	{

		// Disable auto-rendering

		$this->auto_render = FALSE;

	}

	

    public function index()

    {	

		$this->page();

		

    }

    public function page()

    {

    	$language= $this->get_client_lang();

		$this->template->content = new View('news/index');

		$model = new News_Model(); 

		$this->db->where('news_type','1');
		
		$mlist = $model->get_with_active($language);

		//Per page

		if(!isset($per_page))

			$per_page = $this->site['site_num_line']; 

		$this->pagination = new Pagination(array(

			'base_url'    => 'news',

			'uri_segment'    => 'page',

			'total_items'    => count($mlist),

			'items_per_page' => $per_page,

			'style'          => 'digg',

		));	

		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
		
		$this->db->where('news_type','1');

		$mlist = $model->get_with_active($language);
//Press
		$this->db->where('news_type','2');
		$mlistPress = $model->get_with_active($language);

		//Per page

		if(!isset($per_page))

			$per_page = $this->site['site_num_line']; 

		$this->pagination1 = new Pagination(array(

			'base_url'    => 'news',

			'uri_segment'    => 'page',

			'total_items'    => count($mlistPress),

			'items_per_page' => $per_page,

			'style'          => 'digg',

		));	

		$this->db->limit($this->pagination1->items_per_page,$this->pagination1->sql_offset);		
		$this->db->where('news_type','2');
		$mlistPress = $model->get_with_active($language);
		
		$this->template->content->mlist= $mlist;
		
		$this->template->content->mlistPress= $mlistPress;
		//$this->template->content->mlist= $mlist;

		

    }

    public function detail($id)

    {

    	$this->template->content = new View('news/detail');

    	$language = $this->get_client_lang();

		$model = new News_Model(); 

		$this->db->where('news_content.news_id',$id);

		$mlist = $model->get_with_active($language);

    	$this->template->content->mr = $mlist[0];
		$mlistOther = $this->other_news($id);
		//print_r($mlistOther);
		$this->template->content->mlistOther = $mlistOther;

    }
	
	public function other_news($id)

    {

    	$language = $this->get_client_lang();

		$model = new News_Model(); 

		$this->db->where('news_type','1');
		
		$this->db->where('news.news_id <>',$id);

		$mlist = $model->get_with_active($language);
		
		$this->pagination = new Pagination(array(

			'base_url'    => 'news/detail/'.$id,

			'uri_segment'    => 'page',

			'total_items'    => count($mlist),

			'items_per_page' => 10,

			'style'          => 'digg',

		));	

		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
    	$this->db->where('news_type','1');
		$this->db->where('news.news_id <>',$id);

		$mlist = $model->get_with_active($language);
		return $mlist;

    }
	public function press($id)

    {

    	$this->template->content = new View('news/press');

    	$language = $this->get_client_lang();

		$model = new News_Model(); 

		$this->db->where('news_content.news_id',$id);

		$mlist = $model->get_with_active($language);

    	$this->template->content->mr = $mlist[0];
		$mlistOther = $this->other_press($id);
		//print_r($mlistOther);
		$this->template->content->mlistOther = $mlistOther;

    }
	
	public function other_press($id)

    {

    	$language = $this->get_client_lang();

		$model = new News_Model(); 

		$this->db->where('news_type','2');
		
		$this->db->where('news.news_id <>',$id);

		$mlist = $model->get_with_active($language);
		
		$this->pagination = new Pagination(array(

			'base_url'    => 'news/detail/'.$id,

			'uri_segment'    => 'page',

			'total_items'    => count($mlist),

			'items_per_page' => 10,

			'style'          => 'digg',

		));	

		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
    	$this->db->where('news_type','2');
		$this->db->where('news.news_id <>',$id);

		$mlist = $model->get_with_active($language);
		return $mlist;

    }
}

?>